$(function() {
	//Message Box
	$(".msg-nav-a").click(function(e){
		e.stopPropagation();
		if ($(".msg-box").hasClass("is-visible")) {
			$(".msg-box").removeClass("is-visible");
			
		}else{
			$(".msg-box").addClass("is-visible");
			newMessage();
		}
		$(document).one("click", function(){
			if ($(".msg-box").hasClass("is-visible")) {
				$(".msg-box").removeClass("is-visible");
			}
		});
	});	
	$(".msg-box").click(function (e) { 
		e.stopPropagation();
	});
	$(".msg-tab li").on("click",function(){
		$(this).addClass("active").siblings().removeClass("active");
		$(".msg-box section").hide()
		var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content  
        $(activeTab).fadeIn();
		return false;
	})
	
	//$("body").append(contacts());
	$(".addContacts").click(function(){
		$("body").append(contacts());
		$("body").css({"overflow-y":"hidden"});
		$(".contacts-mask").click(function (e) { 
			e.stopPropagation();
		});
		$(".contacts-item").on("click",function(){
			$(this).toggleClass("on");
			
		})
		$(".contacts-close").on("click",function(){
			$(".contacts-mask").remove();
			$("body").css({"overflow-y":"scroll"});
			return false;
		});
		$(".contacts-list input[name='checkbox']").change(function(){
			var result="";
			$("input[name='checkbox']:checked").each(function(){
				   result+=$(this).val()+',';
			});
			if(result!=""){
				result=result.substring(0,result.lastIndexOf(',')); 
			}
			$(".insert").on("click",function(){
				$("#accepter").val(result); 
				$(".contacts-mask").remove();
				$("body").css({"overflow-y":"scroll"});
				return false;
			});
		});
	});

	$(".sendTo").click(function(){
		alert($("#sendMsg").serialize());
		$.ajax({
			type : 'post',
			url : '',
			data: $("#sendMsg").serialize(),
			dataType : 'json',
			success : function(data){
				alert("01");
				if(data.status==0){
					
				}else{
					
				}
			},
			error:function(){
			}
		});
	})
	
});

function replyInput(){
	var html = '';
	html = html + '<p class="msg-replyInput">';
	html = html + '<textarea name="text" maxlength="100" placeholder="Pls reply!"></textarea>';
	html = html + '<input type="submit" name="Submit" value="Send" class="published" />';
	html = html + '</p>';
	return html;
}
function replyCon(replycon){
	//var date = new Date();
	//var time = date.getHours() + ":" + date.getMinutes();
	var html = '';
	html = html + '<p class="msg_cont_rply">Me: ';
	html = html + '<span>'+replycon+'</span>';
	html = html + '</p>';
	return html;
}

function contacts(){
	var html = '';
	html = html + '<div class="contacts-mask">';
	html = html + '<div class="contacts-box">';
	html = html + '<a class="contacts-close">X</a>';
	html = html + '<div class="contacts-title-bar">';
	html = html + '<p class="contacts-title">Contacts</p>';
	html = html + '</div>';
	html = html + '<div class="contacts-list">';
	html = html + '<div class="contacts-item">';
	html = html + '<input type="checkbox" name="checkbox" value="Micah"/>';
	html = html + '<label>Micah"micahcheng@gdoxa.com"</label>';
	html = html + '</div>';
	html = html + '<div class="contacts-item">';
	html = html + '<input type="checkbox" name="checkbox" value="chay"/>';
	html = html + '<label>chay"chay@gdoxa.com"</label>';
	html = html + '</div>';
	html = html + '<div class="contacts-item">';
	html = html + '<input type="checkbox" name="checkbox" value="mozart"/>';
	html = html + '<label>mozart"mozart@gdoxa.com"</label>';
	html = html + '</div>';
	html = html + '</div>';
	html = html + '<div class="contacts-buttons">';
	html = html + '<button type="button" class="button insert">Insert</button>';	
	//html = html + '<button type="button" class="button"></button>';
	html = html + '</div>';
	
	html = html + '</div>';
	html = html + '</div>';
	return html;
}